<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>360商城</title>
		<script src="./Public/Home/js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="./Public/Home/js/index.js" type="text/javascript" charset="utf-8"></script>
  		<script type="text/javascript" charset="utf-8" src="Public/Home/js/jquery.leanModal.min.js"></script>
  		<script src="./Public/Home/hdjs/hdjs.min.js" type="text/javascript" charset="utf-8"></script>
		<link rel="stylesheet" type="text/css" href="Public/Home/css/index.css">
		<link rel="stylesheet" type="text/css" href="Public/Home/hdjs/hdjs.css">
		<link rel="stylesheet" type="text/css" href="Public/Home/css/list.css">
		<script >
			$(function(){
				$(".flatbtn").click(function(){
					$(".bj").fadeToggle(100);
					$(".div").slideToggle(100);
				});

				$(".bj").click(function(){
					$(".div").slideToggle(100);
					$(".bj").fadeToggle(100);

				});

				$(".zq").click(function(){
					var a=$(this).text();
					$.ajax({
						type:"post",
						url:'http://127.0.0.1/project/360/index.php?m=Home&c=index&a=edl',
						data:{cs:a},
						dataType:'json',
						success:function(db){

						}
					})
				});

				$(".btns").click(function(){
					var cs=$(".cs").val();

					var zq=$(this).text();
					alert(zq);
					$.ajax({
						type:"post",
						url:'http://127.0.0.1/project/360/index.php?m=Home&c=index&a=edl',
						data:{cs:cs},
						dataType:'json',
						success:function(db){

						}
					})

				})

			})
		</script>
		
	</head>
	<style type="text/css" media="screen">
		.bj{
			width:100%;
			height:100%;
			position:fixed;
			z-index:1000;
			background:rgba(0,0,0,0.5);
			display:none;
		}

		.div{
			width:300px;
			height:300px;
			background:#fff;
			position:fixed;
			z-index:1001;
			left:33%;
			top:50px;
			display:none;
		}
	</style>
	<body>
	<!--  -->
	<div class="div">
		<input type="text" class="cs" name="">
		<input type="text" class="csa" name="">
		<a class="btns title="">提交</a>
	</div>
	<div class="bj"></div>
	<!-- top头部部分开始 -->
		<div id="top">
			<div class="top">
				<div class="right">
					<ul>
						<!-- <li> <a href="javascript:;" title="" class="flatbtn" id="modaltrigger">登录</a></li> -->
												<li><a href="" title="">sjh</a></li>
						<li> <a href="http://127.0.0.1/project/360/index.php?m=Home&c=Login&a=out" title="">退出</a></li>
												<li> <a href="" title="">我的订单</a></li>
					</ul>
				</div>
			</div>
		</div>
		<!-- logo购物车部分开始 -->
		<div id="search">
			<div class="logo">
				<a href="http://127.0.0.1/project/360/index.php?m=Home&c=Index&a=index" title=""><img src="./Public/Home/images/logo.png" alt=""></a>
			</div>
			<!-- 搜索框部分开始 -->
			<div class="header_search">
				<div class="form">
					<form action="" method="post" accept-charset="utf-8">
						<input class="input" type="text" name="q" placeholder="360行车记录仪">
						<input class="submit" type="submit" value="">
					</form>
				</div>
				<div class="shopcar">
					<div class="gwc">
						<a href="http://127.0.0.1/project/360/index.php?m=Home&c=Cart&a=index" title=""><i></i>我的购物车<span class="num1">(1)</span></a>
					</div>
					<div class="gwchtc">
												<a href="javascript:;" title="">您的购物车没有东西<span>(0)</span></a>
											</div>
				</div>
				<div class="hot">
				<a href="">智能出行伴侣</a><a href="">智能出行伴侣</a><a href="">智能出行伴侣</a>
				</div>
			</div>
			<script>
				$(function () {
					//异步删除购物车中的商品
					$(".del").click(function () {
						var sid=$(this).attr('sid');
						$.ajax({
							type:'post',
							url:'http://127.0.0.1/project/360/index.php?m=Home&c=Cart&a=del',
							data:{c:sid},
							dataType:'json',
							success:function (e) {
								var a="("+e.num+")";
								var b='<a href="javascript:;" title="">您的购物车没有东西<span>(0)</span></a>';
								if(e.num==0){
									$(".gwchtc").html(b);
								}else{
									$(".red1").html(e.num);
								}

								$(".num1").html(a);
								$(".red2").html(e.pri);
							}

						});
						$(this).parents('.lf').remove();
					});
				})
			</script>
			
		</div>
		<!-- top购物车部分结束 -->
		<!-- top分类部分开始 -->
		<div id="cate">	
			<div id="top_cate">
			<div class="cate">
				<a href=""> 全部智能酷品</a>
			</div>
			<ul>
								<li><a href="http://127.0.0.1/project/360/index.php?m=Home&c=List&a=index&cid=1" title="">手机及配件</a></li>
								<li><a href="http://127.0.0.1/project/360/index.php?m=Home&c=List&a=index&cid=4" title="">智能手表</a></li>
								<li><a href="http://127.0.0.1/project/360/index.php?m=Home&c=List&a=index&cid=5" title="">行车记录仪</a></li>
								<li><a href="http://127.0.0.1/project/360/index.php?m=Home&c=List&a=index&cid=6" title="">电脑设备</a></li>
								<li><a href="http://127.0.0.1/project/360/index.php?m=Home&c=List&a=index&cid=7" title="">智能机器人</a></li>
								<li><a href="http://127.0.0.1/project/360/index.php?m=Home&c=List&a=index&cid=19" title="">智能家居</a></li>
								<li><a href="http://127.0.0.1/project/360/index.php?m=Home&c=List&a=index&cid=20" title="">影音娱乐</a></li>
								<li><a href="http://127.0.0.1/project/360/index.php?m=Home&c=List&a=index&cid=21" title="">母婴玩具</a></li>
							</ul>
			</div>
		</div>

<link rel="stylesheet" href="./Public/Home/css/car.css">
<!-- 公共部分结束 -->
<div id="my_car">
    <?php if(!isset($_SESSION['cart']['goods'])){ ?>
    <div class="car">
        <h3>我的购物车</h3>
    </div>
    <div class="bd">
        <div class="cartEmpty">
            <a href="<?php echo U('Index')?>" title="马上去购物" class="toShoping"></a>
        </div>
    </div>
    <?php }else{ ?>
    <div class="car">
        <h3>我的购物车</h3>
    </div>
    <div class="car_list">
        <div class="title">
            <ul>
                <li class="lit">商品信息</li>
                <li>单价</li>
                <li>数量</li>
                <li>小计</li>
                <li>操作</li>
            </ul>
        </div>
    </div>

    <div class="list">
        <?php foreach ($_SESSION['cart']['goods'] as $k=>$v){?>
        <ul class="rp">
            <li class="lit">
                <div class="img">
                    <img src="<?php echo $v['options']['pic']?>" alt="">
                </div>
                <a href="<?php echo U('Content/index',['gid'=>$v['id']])?>" title=""><?php echo $v['name']?></a>
            </li>
            <li class="dj"><span><?php echo $v['price']?></span>元</li>
            <li><button class="min" type="button">-</button><input class="z" type="text" name="" sid="<?php echo $k?>" value="<?php echo $v['num']?>"><button class="max" type="button">+</button></li>
            <li class="xj"><span id="montol"><?php echo $v['total']?></span>元</li>
            <li><a class="del" href="javascript:;" sid="<?php echo $k?>">删除</a></li>
        </ul>
        <?php }?>
    </div>
    <!-- 商品价格总计 -->
    <div class="count">
        <div class="money">
            <p>商品总计:<span id="last"><?php echo $_SESSION['cart']['total']?></span>元</p>
        </div>
        <div class="btn">
            <a href="<?php echo U('Index/index')?>" class="b1" title="继续购物">继续购物</a>
            <a href="javascript:void(0);" class="b2" title="去结算">去结算</a>
            <?php $_SESSION['url']=$_SERVER['HTTP_REFERER']; ?>
        </div>
    </div>
    <?php } ?>
</div>
<br>
    <script>

        $(function(){
            $(".max").click(function(){
                var t=  $(this).parent().find(".z"); //根据这个来找到它相对的元素 当然也可以直接 //$(this).prev(); 这个直接来找到
                t.val(parseInt(t.val())+1);
                //异步购物车编辑
                var zhi=t.val();
                var sid=t.attr('sid');
                var arr=[zhi,sid];
//                console.log(arr);
                $.ajax({
                    type:'post',
                    url:'<?php echo U("Cart/edit")?>',
                    data:{c:arr},
                    dataType:'json',
                    success:function (e) {
                        $("#last").html(e);
                    }
                });
                setTotal($(this),t.val());

            });
            $(".min").click(function(){
                var t=  $(this).parent().find(".z"); //根据这个来找到它相对的元素 当然也可以直接 //$(this).next(); 这个直接来找到
                if(parseInt(t.val())==1){
                    return;
                }
                t.val(parseInt(t.val())-1);
                var zhi=t.val();
                var sid=t.attr('sid');
                var arr=[zhi,sid];
                $.ajax({
                    type:'post',
                    url:'<?php echo U("Cart/edit")?>',
                    data:{c:arr},
                    dataType:'json',
                    success:function (e) {
                        $("#last").html(e);
                    }
                });
                setTotal($(this),t.val());
            });
            //获得当前商品的总价
            function setTotal(obj,number){
                var total=number*$(obj).parent().parent().find(".dj span").text(); //这里算出总价
                $(obj).parent().parent().find(".xj").html(total.toFixed(2));
            }
            //异步删除购物车中的商品
            $(".del").click(function () {
                var sid=$(this).attr('sid');
//                alert(sid);
                    $.ajax({
                        type:'post',
                        url:'<?php echo U("Cart/del")?>',
                        data:{c:sid},
                        dataType:'json',
                        success:function (e) {
                            $("#last").html(e.num);
                    }

                });
                $(this).parents('.rp').remove();
            });
            //购物车去结算
            $(".b2").click(function () {
                var a=1;
                $.ajax({
                    type:'post',
                    url:'<?php echo U("Cart/check")?>',
                    data:{c:a},
                    success:function (e) {
                        if(e==1){
                            alert("请先去登录");
                            location.href="<?php echo U('Login/login')?>";
                        }
                        if(e==0){
                            location.href="<?php echo U('Order/index')?>"
                        }
                    }
                })
            })

        })

    </script>

<!-- 7天无理由退货部分 -->
<div id="ser">
    <div class="ser">
        <div class="li">
            <i>7</i><span>7天无理由退货</span>
        </div>
        <div class="li">
            <i>15</i><span>15天免费换货</span>
        </div>
        <div class="li lin">
            <i>包</i><span>7满99元包邮</span>
        </div>
    </div>
</div>
<div id="footer">
    <div class="ft">
        <br>
        <br>
        <br>
        <p>360商城©2013-2016 360公司版权所有 京ICP备08010314号-43 京公网安备11000002000006号奇酷互联网络科技（深圳）有限公司 0755-61898999 深圳市南山区学苑大道1001号南山智园A2栋</p>
    </div>
</div>
</body>
</html>